﻿@{
    Layout = "~/Views/Shared/OA/_Splitter.cshtml";
}
@section Toolbar
{
    @Html.MyNet().Button(new ButtonOptions { Text = "新建", Power = "CMS_Article_Create" })
    @Html.MyNet().Button(new ButtonOptions { Text = "审核通过", Power = "CMS_Article_Audit", Click = "pass" })
    @Html.MyNet().Button(new ButtonOptions { Text = "审核不通过", Power = "CMS_Article_Audit", Click = "unPass" })
    @Html.MyNet().Button(new ButtonOptions { Text = "移动", Power = "CMS_Article_Modify", Click = "move" })
    @Html.MyNet().Button(new ButtonOptions { Text = "转链", Power = "CMS_Article_Modify", Click = "transfer" })
    @Html.MyNet().Button(new ButtonOptions { Text = "删除", Power = "CMS_Article_Remove", Click = "removee" })
}
@section Menu
{
    @*@Html.MyNet().Menu(new ButtonOptions { Text = "查看详细", Click = "detail" })*@
    @Html.MyNet().Menu(new ButtonOptions { Text = "修改", Power = "CMS_Article_Modify" })
    @Html.MyNet().Menu(new ButtonOptions { Text = "移动", Power = "CMS_Article_Modify", Click = "move" })
    @Html.MyNet().Menu(new ButtonOptions { Text = "转链", Power = "CMS_Article_Modify", Click = "transfer" })
    @Html.MyNet().Menu(new ButtonOptions { Text = "审核通过", Power = "CMS_Article_Audit", Click = "pass" })
    @Html.MyNet().Menu(new ButtonOptions { Text = "审核不通过", Power = "CMS_Article_Audit", Click = "unPass" })
    @Html.MyNet().Menu(new ButtonOptions { Text = "评论", Power = "CMS_Article_Comment" })
    @Html.MyNet().Menu(new ButtonOptions { Text = "关联", Power = "CMS_Article_Associate" })
    @Html.MyNet().Menu(new ButtonOptions { Text = "删除", Power = "CMS_Article_Remove", Click = "removee" })
}
@section Query
{
    @Html.Partial("_Query", new ArticleCondition())
}
@section Tree
{
    <div id="tree" class="tree">
    </div>
}
@section Main
{
    <div id="grid" class="grid">
    </div>
    <div id="pager" class="pager">
    </div>
}
<script type="text/javascript">

    var url = "/CMS/Article/";
    var urlCatalog = "/CMS/Catalog/";

    jQuery(function ()
    {
        $("#tree").kendoTreeView(
        {
            dataSource:
            {
                transport: { read: urlCatalog + "ReadForParent?ParentKey=Article_EN" },
                schema:
                {
                    data: "Data",
                    model: { children: "childs" },
                    errors: "Errors"
                },
                error: function (e)
                {
                    alert(e.errors);
                }
            },
            dataBound: onDataBound,
            select: onSelect,
            dragend: onDragend
        });
    });

    function read()
    {
        query.catalogId = treeSelected();

        $.ajax
        ({
            url: url + "Read",
            data: query,
            type: "post",
            error: disposeError,
            success: function (result)
            {

                if (disposeException(result)) return;
                bind(result);
            }
        });
    }

    function create()
    {
        if (treeSelected())
        {
            nav(url + "Create?CatalogId=" + treeSelected());
        }
        else
        {
            nav(url + "Create");
        }
    }

    function modify()
    {
        if (!gridSelected()) return alert("未选中任何数据！");
        nav(url + "Modify?Id=" + gridSelected());
    }

    function move()
    {
        if (!gridSelected()) return alert("未选中任何数据！");
        nav(url + "Move?Ids=" + gridSelected().join(','));
    }

    function transfer()
    {
        if (!gridSelected()) return alert("未选中任何数据！");
        nav(url + "Transfer?Ids=" + gridSelected().join(','));
    }

    function comment()
    {
        var commentCatalogKey = gridSelectedHidden("CommentCatalogKey");
        if (commentCatalogKey.toString().length == 0) return alert("该栏目未配置所评论栏目！");

        if (!gridSelected()) return alert("未选中任何数据！");
        nav(url + "Comment?Id=" + gridSelected());
    }

    function associate()
    {
        var associationCatalogKey = gridSelectedHidden("AssociationCatalogKey");
        if (associationCatalogKey.toString().length == 0) return alert("该栏目未配置所关联信息栏目！");

        if (!gridSelected()) return alert("未选中任何数据！");
        nav(url + "Association?AssociationId=" + gridSelected());
    }

    //function detail()
    //{
    //    if (!gridSelected()) return alert("未选中任何数据！");
    //    nav(url + "Detail?Id=" + gridSelected());
    //}

    function removee()
    {
        if (!gridSelected()) return alert("未选中任何数据！");
        if (!confirm("确定要删除选中的数据吗？")) return;

        $.ajax
        ({
            url: url + "Remove",
            data: { ids: gridSelected() },
            type: "post",
            error: disposeError,
            success: function (result)
            {
                if (disposeException(result)) return;

                read();
            }
        });
    }

    function pass()
    {
        if (!gridSelected()) return alert("未选中任何数据！");

        $.ajax
        ({
            url: url + "Pass",
            data: { ids: gridSelected() },
            type: "post",
            error: disposeError,
            success: function (result)
            {
                if (disposeException(result)) return;

                read();
            }
        });
    }

    function unPass()
    {
        if (!gridSelected()) return alert("未选中任何数据！");

        $.ajax
        ({
            url: url + "UnPass",
            data: { ids: gridSelected() },
            type: "post",
            error: disposeError,
            success: function (result)
            {
                if (disposeException(result)) return;
                read();
            }
        });
    }

</script>
